var table;
$(function() {
	table = dataTable.init('table', {
		url : RS.webPath + '/admin/rsRoles/query',
		toolbar : '#toolbar',
		cols : [ [ {
			checkbox : true,
			fixed : true
		}, {
			field : 'roleId',
			title : '角色id',
			fixed : 'left'
		}, {
			field : 'roleName',
			title : '角色名',
			fixed : 'left',
		}, {
			field : 'description',
			title : '说明',
			fixed : 'left'
		}, {
			field : 'ctime',
			title : '创建时间',
			fixed : 'left',
			templet : function(val) {
				return timeds(val.ctime);
			}
		}, {
			field : 'updateTime',
			title : '更新时间',
			fixed : 'left',
			templet : function(val) {
				return timeds(val.updateTime);
			}
		} ] ]
	});
});
function query() {
	table.search({
		roleName : $('#roleName').val()
	});
}
function add() {
	window.location.href = webPath + '/admin/rsRoles/edit?method=INSERT';
}
function del() {
	var selections = table.getAllSelected();
	if (selections.length < 1) {
		parent.layer.alert("您未选择任何一条记录");
		return;
	}
	var ids = [];
	for (var i = 0; i < selections.length; i++) {
		ids[i] = selections[i].roleId
	}
	parent.layer.confirm("是否要删除选中的项目？", {
		icon : 3,
		title : '提示',
	}, function(index) {
		$.ajax({
			url : webPath + '/admin/rsRoles/del',
			type : 'post',
			dataType : 'json',
			data : '__paramSet__=' + JSON.stringify(ids),
			success : function(ret) {
				if (ret.status == 0) {
					parent.layer.alert('删除失败');
				} else {
					parent.layer.alert('删除成功');
				}
			}
		});
		query();
	});
}
function editRole() {
	var selections = table.getAllSelected();
	if (selections.length != 1) {
		parent.layer.alert("只能选择一个项目进行编辑");
		return;
	}
	var id = selections[0].roleId;
	// window.location.href = webPath + '/admin/rsRoleMenu?role_id=' + id;
	parent.layer.open({
		type : 2,
		title : '编辑权限',
		shadeClose : true,
		shade : 0.8,
		area : [ '380px', '90%' ],
		content : webPath + '/admin/rsRoleMenu/getRoleMenu?role_id=' + id, // iframe的url，no代表不显示滚动条
	});
}
function edit() {
	var selections = table.getAllSelected();
	if (selections.length != 1) {
		parent.layer.alert("只能选择一个项目进行编辑");
		return;
	}
	var id = selections[0].roleId;
	window.location.href = webPath + '/admin/rsRoles/edit?method=UPDATE&id='
			+ id;
}
